//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		account:app.setting.account,
		pagetitle:'代付详情' + '-' + app.setting.title,
		
	},
	onReady: function (){
	},
	onLoad: function (opt){
		var page=this;
		var route=page.route;
		page.setData({
			route:route,
		});
		if(opt.orderid){
			var path=route.slice(0,-6).split('/');
			app.access.plugin=path.shift();
			app.access.action=path.join('.');
			app.access.query =app.util.made_query(opt,true);
			app.access.op=opt.op?opt.op:'';
		}
		wx.setNavigationBarTitle({'title':page.data.pagetitle});
		app.util.get(app.access,function(pagedata){
			console.log('peerpay_pay');console.log(pagedata);	
			page.setData({
				pagedata:pagedata
			});
		});
	},
	settype: function (e) {
		var the=this;
		var pagedata=the.data.pagedata;
		var data = e.currentTarget.dataset;
		this.setData({
				'pagedata.item.type':data.type,
		});
		
	},
	setremark: function (e) {
		var the=this;
		var pagedata=the.data.pagedata;
		var remark = e.detail.value;
		this.setData({
				'pagedata.item.remark':remark,
		});
		
	},
	setmoney: function (e) {
		var the=this;
		var pagedata=the.data.pagedata;
		var money = e.detail.value;
		this.setData({
				'pagedata.item.money':money,
		});
		
	},
	post:function(){
		var page=this
		var pagedata=page.data.pagedata
		app.util.post('jy_weishop/order.peerpay/post/',pagedata.item);
	},
	closepaymodal:function(){
		var page=this
		page.setData({
				showpaymodal:false
		});
	},
	pay_credit:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_credit(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}else{
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}
		})
	},
	pay_wechat:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_wechat(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}else{
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}
		})
	},
	pay_alipay:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_alipay(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}else{
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}
		})
	},
	pay_hdfk:function(e){
		var page=this
		var data=e.currentTarget.dataset;
		app.util.pay_hdfk(data.id,function(res){
				page.setData({
						showpaymodal:false,
				});
				if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}else{
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}
		})
	},
	setpay:function(e){
		var page=this
		var pagedata=page.data.pagedata
		var data=e.currentTarget.dataset;
		app.util.post('jy_weishop/order.peerpay_pay/post/',pagedata.item,function(payid){
			app.util.pay(payid,function(res){		
				if(res.type=='more'){
					page.setData({
						showpaymodal:true,
						'pagedata.paymodal':res
					});
				}else if(res.type=='success'){
					app.util.msg(res.message,'','jy_weishop/order.peerpay_pay/');
				}else{
					app.util.msg(res.message);
				}
			});
		});
	},
	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	onShareAppMessage: function (res) {
		var the = this
		var pagedata = the.data.pagedata
		if (res.from === 'button') {
		}
		var path='/jy_weishop/order/peerpay_pay/index?orderid='+pagedata.orderid;
		if(pagedata.fromuser){
			path +='&fromuser='+pagedata.fromuser;
		}
		return {
		  title: pagedata.sharedata.title,
		  path: path,
		  desc: pagedata.sharedata.desc,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	},
	onShareTimeline: function (res) {
		var the = this
		var pagedata = the.data.pagedata
		var query=app.access.query
		query +='&orderid='+pagedata.orderid;
		if(pagedata.fromuser){
			query +='&fromuser='+pagedata.fromuser;
		}
		query +='&isgoshare=1'
		return {
		  title: pagedata.sharedata.title,
		  query: query,
		  desc: pagedata.sharedata.desc,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	},
});